import React, { useEffect } from 'react'
import Son1 from './Son1'
import Son2 from './Son2'
import PubSub from 'pubsub-js';
export default function Father() {
    useEffect(() => {
        // 订阅消息
        let fanId = PubSub.subscribe('fanfan', (msg, data) => {
            console.log('Father msg: ', msg);
            console.log('Father data: ', data);
        })
        return () => {
            PubSub.unsubscribe(fanId);// 组件销毁前取消订阅
        }
    }, []);
    return (
        <div>
            <h4>Father</h4>
            <Son1 />
            <hr />
            <Son2 />
        </div>
    )
}
